package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.StrategyStatisPersistenceVO;
import cn.wolfcode.luowowo.cache.service.IStrategyRedisService;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import cn.wolfcode.luowowo.common.util.BeanUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Redis数据落地/持久化
 * @author hslef
 */
//@Component
public class RedisDataPersistentTask {

    @Reference
    private IStrategyDetailService strategyDetailService;

    @Reference
    private IStrategyRedisService strategyRedisService;

    @Scheduled(cron = "0/20 * * * * *")
    public void strategyDataPersistent(){
        System.out.println("----------开始-------------");
        List<StrategyStatisVO> statisVOS =  strategyRedisService.queryStatisVos();
        for (StrategyStatisVO statisVO : statisVOS) {
            StrategyStatisPersistenceVO persistenceVO = new StrategyStatisPersistenceVO();
            BeanUtil.copyProperties(persistenceVO,statisVO);
            strategyDetailService.updateStatis(persistenceVO);
        }
        System.out.println("----------结束-------------");
    }

}
